#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution
{
public:
    bool checkValidCuts(int n, vector<vector<int>> &rectangles) // x,y,x',y'
    {
        vector<pair<int, int>> xRanges(rectangles.size());
        vector<pair<int, int>> yRanges(rectangles.size());
        for (int i = 0; i < rectangles.size(); i++)
        {
            xRanges[i].first = rectangles[i][0];
            xRanges[i].second = rectangles[i][2];
            yRanges[i].first = rectangles[i][1];
            yRanges[i].second = rectangles[i][3];
        }
        sort(xRanges.begin(), xRanges.end());
        int maxRight = xRanges[0].second;
        int gap = 0;
        for (auto xRange : xRanges)
        {
            if (xRange.first >= maxRight)
            {
                gap += 1;
                maxRight = xRange.second;
            }
            else
            {
                maxRight = max(maxRight, xRange.second);
            }
            if (gap > 1)
                return true;
        }
        sort(yRanges.begin(), yRanges.end());
        maxRight = yRanges[0].second;
        gap = 0;
        for (auto yRange : yRanges)
        {
            if (yRange.first >= maxRight)
            {
                gap += 1;
                maxRight = yRange.second;
            }
            else
            {
                maxRight = max(maxRight, yRange.second);
            }
            if (gap > 1)
                return true;
        }
        return false;
    }
};

int main()
{
    cout << "Code3394" << endl;
    Solution s; //[[0,2,2,4],[1,0,3,2],[2,2,3,4],[3,0,4,2],[3,2,4,4]]
    vector<vector<int>> rectangles = {{0, 2, 2, 4}, {1, 0, 3, 2}, {2, 2, 3, 4}, {3, 0, 4, 2}, {3, 2, 4, 4}};
    cout << s.checkValidCuts(4, rectangles) << endl;
    return 0;
}